package com.yang.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.yang.domain.dto.user.RegisterUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户表
 * @TableName user
 */
@TableName(value ="user")
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "User", description = "用户模型")
public class User implements Serializable {
    /**
     * 用户编号
     */
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "用户编号")
    private Integer id;

    /**
     * 账号
     */
    @ApiModelProperty(value = "账号")
    private String username;

    /**
     * 密码
     */
    @ApiModelProperty(value = "密码")
    private String password;

    /**
     * 昵称
     */
    @ApiModelProperty(value = "昵称")
    @TableField(fill = FieldFill.INSERT)
    private String nickName;

    /**
     * 头像
     */
    @ApiModelProperty(value = "头像")
    @TableField(fill = FieldFill.INSERT)
    private String header;

    /**
     * 性别(1男、0女)
     */
    @ApiModelProperty(value = "性别(1男、0女)")
    @TableField(fill = FieldFill.INSERT)
    private Integer gender;

    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    private String email;

    /**
     * 是否是管理员(0是、1否)
     */
    @ApiModelProperty(value = "是否是管理员(0是、1否)")
    @TableField(fill = FieldFill.INSERT)
    private Integer isAdmin;

    /**
     * 更新者id
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "更新者编号")
    private Integer updateBy;

    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 上次登陆时间
     */
    @ApiModelProperty(value = "上次登陆时间")
    private LocalDateTime lastLoginTime;

    /**
     * 逻辑删除列(0正常、1删除)
     */
    @ApiModelProperty(value = "逻辑删除列(0正常、1删除)")
    @TableField(fill = FieldFill.INSERT)
    private Integer delFlag;

    @ApiModelProperty(value = "token",required = false)
    @TableField(exist = false)
    private String token;

    @ApiModelProperty(value = "关联车辆",required = false)
    @TableField(exist = false)
    private List<Car> carList;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public User(RegisterUser registerUser) {
        this.username = registerUser.getEmail();
        this.email = registerUser.getEmail();
        this.nickName = registerUser.getNickName();
        this.gender = registerUser.getGender();
        this.password = registerUser.getPassword();
        this.isAdmin = registerUser.getIsAdmin();
    }
}